package sliver.action.shop;

import java.io.Serializable;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import sliver.entity.Shopper;
import sliver.service.shop.vip.ShopVipService;

import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller("shop.addShopVipAction")
public class AddShopVipAction extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = -5521473161131232418L;
	
	private Long customId;
	
	private Map<String, Object> session;
	
	@Autowired
	private ShopVipService shopVipService;
	
	public AddShopVipAction(){
		
	}

	public Long getCustomId() {
		return customId;
	}

	public void setCustomId(Long customId) {
		this.customId = customId;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	@Override
	public String execute() throws Exception {
		
		Shopper shopper = Shopper.class.cast(session.get("login_shopper"));
		
		Serializable id = shopVipService.addShopVip(shopper.getId(), customId);
		if(id != null){
			return SUCCESS;
		}
		
		return ERROR;
	}
	
}
